package com.jf3q.front.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jf3q.common.domain.EduOrder;
import com.jf3q.common.utils.JwtTokenUtil;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.front.service.EduOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Tag(name = "后台订单模块")
public class OrderController {


    @Autowired
    EduOrderService eduOrderService;


    @Autowired
    JwtTokenUtil jwtTokenUtil;

    /*
    * 根据课程id和用户id创建订单，返回订单id(生成订单)
    * */
    @PostMapping("/createOrder/{courseId}/{memberId}")
    @Operation(summary = "订单接口")
    public ResultVo createOrder(@PathVariable String courseId, @PathVariable String memberId){
        //创建订单，返回订单号
        String orderNo =eduOrderService.createOrders(courseId,memberId);
        return ResultVo.success("成功",orderNo);
    }



    /*
    * 根据订单id查询订单信息
    * */
    @Operation(summary = "查询订单信息")
    @GetMapping("/getOrderInfo/{orderId}")
    public ResultVo getOrderInfo(@PathVariable String orderId){
        LambdaQueryWrapper<EduOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EduOrder::getOrderNo,orderId);
        EduOrder order = eduOrderService.getOne(queryWrapper);
        return ResultVo.success("item",order);
    }
}
